<?php
/**
 * Created by PhpStorm.
 * User: qttx
 * Date: 2019/5/30
 * Time: 13:58
 */
namespace app\api\model;
use think\Db;
class BuyorderModel extends BaseModel
{
    protected $table = "xst_buy_order";
    protected $rule = [
        'id' => '',
    ];
    protected $msg = [
        'id' => '',
    ];
    /**买单查询*/
    public function buyorder($data,$page)
    {
        $buyorder = $this->field('bo.*,u.Picture')->alias('bo')->join('xst_user u','bo.uid = u.id')->where($data)->limit(0,$page*10)->order('createtime', 'desc')->select();
        foreach ($buyorder as $key=>$val)
        {
            $order_number = substr($val['order_number'],-4,4);
            $buyorder[$key]['order_numbers']='*********'.$order_number;
            //$buyorder[$key]['way'] = explode(',',$val['way']);
        }
        return $buyorder;
    }
    /**卖单查询*/
    public function sellorder($data,$page)
    {
        $buyorder = $this->field('bo.*,u.Picture')->alias('bo')->join('xst_user u','bo.to_uid = u.id')->where($data)->limit(0,$page*10)->order('createtime', 'desc')->select();
        foreach ($buyorder as $key=>$val)
        {
            $order_number = substr($val['order_number'],-4,4);
            $buyorder[$key]['order_numbers']='**********'.$order_number;
            //$buyorder[$key]['way'] = explode(',',$val['way']);
        }
        return $buyorder;
    }
    /**发布**/
    public function buyorder_add($add)
    {
        $buyorder_add = $this->insert($add);
        return $buyorder_add;
    }
    /**是否设置支付密码**/
    public function paypwd($data)
    {
        $paypwd = Db::name('user')->where($data)->find();
        return $paypwd;
    }
    /**添加支付密码**/
    public function paypwd_update($data,$add)
    {
        $paypwd_update = Db::name('user')->where($data)->update($add);
        return $paypwd_update;
    }

    /**买卖单详情*/
    public function buylist($data)
    {
        $buylist = $this->where($data)->find();
        return $buylist;
    }

    /**买卖单修改**/
    public function buyorder_update($data,$upd)
    {
        $buyorder_update = $this->where($data)->update($upd);
        return $buyorder_update;
    }

    /**流水表**/
    public function balance_log($add)
    {
        $balance_log = Db::name('balance_log')->insert($add);
        return $balance_log;
    }

    /**会员余额表查询**/
    public function balance_list($list)
    {
        $balance_list = Db::name('balance')->where($list)->find();
        return $balance_list;
    }
    /**会员余额表修改**/
    public function balance_update($list,$upd)
    {
        $balance_update = Db::name('balance')->where($list)->update($upd);
        return $balance_update;
    }
      /**添加释放表**/
    public function release_add($add)
    {
        $release_add = Db::name('release')->insert($add);
        return $release_add;
    }
}